<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('节假日名称')" prop="name" style="width:80%">
            <el-input v-model="form.name" :placeholder="$t('节假日名称')" :maxlength="50" show-word-limit />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('日期')" prop="vacationsDate" style="width:80%">
            <DatePicker
              v-model="form.vacationsDate"
              :placeholder="$t('日期')"
              style="width:100%"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark" style="width:80%">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" :maxlength="2000" show-word-limit />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <SaveBtn has-permi="oa:holiday" />
    </div>
  </div>
</template>

<script>
    import { saveOaVacationHoliday, getOaVacationHoliday } from '@/api/oa/vacation/holiday/oaVacationHoliday'
    export default {
        props: {
          oaVacationHolidayData: {
            type: Object,
            default: null
          }
        },
        data() {
            return {
                // 表单参数
                form: {},
              loading: false,
                // 表单校验
                rules: {
                  name: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  vacationsDate: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ]
                }
            }
        },
        watch: {
             oaVacationHolidayData: function() {
                this.form = this.oaVacationHolidayData
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(id) {
                this.loading = true
                if (id != null && id !== '') {
                    getOaVacationHoliday(id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                name: undefined,
                vacationsDate: undefined,
                remark: undefined,
                delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveOaVacationHoliday(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.$parent.$parent.formOpen = false
                                this.$parent.$parent.getList()
                            } else {
                                this.msgError(response.msg)
                            }
                          this.loading = false
                        }).catch(() => {
                          this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
            }
        }

    }
</script>
